package com.ormlite.pojo;

import android.widget.EditText;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.ormlite.activity.tool.Utils;

@DatabaseTable(tableName = "movie")
public class Movie {

	@DatabaseField(generatedId = true, index = true)
	private int id;
	@DatabaseField(canBeNull = false)
	private String title;
	@DatabaseField
	private Integer year;
	@DatabaseField(defaultValue = "unknown")
	private String director;
	@DatabaseField(canBeNull = true)
	private Double rate;

	public Movie() {
		// ORMLite needs a no-arg constructor
	}

	public Movie(String title, Integer year, String director, Double rate) {
		this.title = title;
		this.year = year;
		this.director = director;
		this.rate = rate;
	}

	public int getId() {
		return id;
	}

	public String getTitle() {
		return title;
	}

	public void setFullTitle(String title) {
		this.title = title;
	}

	public Integer getYear() {
		return year;
	}

	public void setYear(Integer year) {
		this.year = year;
	}

	public String getDirector() {
		return director;
	}

	public void setDirector(String director) {
		this.director = director;
	}

	public Double getRate() {
		return rate;
	}

	public void setRate(Double rate) {
		this.rate = rate;
	}

	public static Movie createMovie(EditText... edits) {
		
		String title = edits[Utils.NTITLE].getText().toString();
		String director = edits[Utils.NDIRECTOR].getText().toString();
		Integer year = Utils.toInteger(edits[Utils.NYEAR].getText().toString());
		Double rate = Utils.toDouble(edits[Utils.NRATE].getText().toString());

		return new Movie(title, year, director, rate);
	}
}